<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="应收期间">
              <a-month-picker style="width: 100%;" :disabled-date="disabledDate" valueFormat = 'YYYY-MM' placeholder="请选择应收期间" picker="month" :allowClear="false" v-model="queryParam.collectionDateBegin" @change="dateChange" />
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="项目编号">
              <a-input placeholder="请输入项目编号" v-model="queryParam.projectNo"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="项目名称">
              <j-input placeholder="请输入项目名称" v-model="queryParam.projectName"></j-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="项目负责人">
              <select-user-by-dep  placeholder="请选择项目负责人" :multi="false" v-model="queryParam.projectLeading" />
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="年度">
              <j-dict-select-tag type="list" v-model="queryParam.year" dictCode="yjgsnd" placeholder="请选择年度"/>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="现属经营团队">
              <select-team-input placeholder="请选择现属经营团队" v-model="queryParam.teamName" :tdlx="1" :teamType="0"/>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="项目承接人">
              <select-user-by-dep  placeholder="请选择项目承接人" :multi="false" v-model="queryParam.undertaker" />
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="是否完全回款">
              <j-dict-select-tag type="list" v-model="queryParam.noCollectMoney" dictCode="YES_OR_NO" placeholder="请选择是否完全回款"/>
            </a-form-item>
          </a-col>
          <!-- <template v-if="toggleSearchStatus"></template> -->
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <!-- <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a> -->
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->
    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button :loading="exportLoading" type="primary" icon="download" @click="handleExportXlnew('关注类应收账款')"
                >导出
      </a-button>
      <a-popover title="自定义列" trigger="click" placement="leftBottom">
        <template slot="content">
          <a-checkbox-group @change="onColSettingsChange" v-model="settingColumns" :defaultValue="settingColumns">
            <a-row>
              <template v-for="(item, index) in defColumns">
                <template v-if="item.key!='rowIndex'&& item.dataIndex!='action'">
                  <a-col :span="12" :key="index">
                    <a-checkbox :value="item.dataIndex">{{ item.title }}</a-checkbox>
                  </a-col>
                </template>
              </template>
            </a-row>
          </a-checkbox-group>
        </template>
        <a style="float: right;">
          <a-icon type="setting" :style="iconStyle"/>
        </a>
      </a-popover>
    </div>
    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a
        style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>
      <a-table
        ref="table"
        size="middle"
        :scroll="{x:scrollX}"
        bordered
        :components="draggableComponent"
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        class="j-table-force-nowrap"
        :customRow="customRow"
        @change="handleTableChange">
        <template slot="status" slot-scope="status">
          <a-badge :status="status | statusTypeFilter" :text="status | statusFilter"/>
        </template>
        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt=""
              style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="pcaSlot" slot-scope="text">
          <div>{{ getPcaText(text) }}</div>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>
          <span slot="action" slot-scope="text, record">
            <a-button
              type="link"
              @click="handleEdit(record)"
            >查看督办</a-button>
          </span>
      </a-table>
    </div>
    <supervision-list ref= "supervisionList" @close="handleClose"></supervision-list>
  </a-card>
</template>
<script>
import '@/assets/less/TableExpand.less'
import { mixinDevice } from '@/utils/mixin'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import { downFile, getAction } from '@/api/manage'
import Area from '@/components/_util/Area'
import { DisabledAuthFilterMixin } from '@/mixins/DisabledAuthFilterMixin'
import SelectTeamInput from '@views/scy/components/SelectTeamInput'
import SelectUserByDep from '@/views/scy/components/SelectUserByDep'
import SelectCustomerInput from '@views/scy/components/SelectCustomerInput'
import BusinessCategoryNameSelect from '@views/erp/components/BusinessCategoryNameSelect'
import SelectCompanyInput from '@/views/scy/components/SelectCompanyInput'
import SupervisionList from './modules/SupervisionList' // 督办列表
import moment from 'moment'
export default {
  name: 'ErpOmcProjectList',
  mixins: [JeecgListMixin, mixinDevice, DisabledAuthFilterMixin],
  components: {
    SelectTeamInput,
    SelectUserByDep,
    SelectCustomerInput,
    BusinessCategoryNameSelect,
    SelectCompanyInput,
    SupervisionList
  },
  data() {
    return {
      /* 排序参数 */
      isorter: {
        column: '',
        order: ''
      },
      description: '立项档案信息管理页面',
      //表头
      columns: [],
      //列设置
      settingColumns: [],
      // 列定义
      defColumns: [
        {
          title: '序号',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          // fixed: 'left',
          ellipsis: true,
          customRender: function (t, r, index) {
            return parseInt(index) + 1;
          }
        },
        {
          title: '应收期间',
          align: 'center',
          dataIndex: 'collectionDate',
          ellipsis: true,
          width: 135,
        },
        {
          title: '项目编号',
          align: 'center',
          dataIndex: 'projectNo',
          ellipsis: true,
          width: 135,
        },
        {
          title: '项目名称',
          align: 'center',
          dataIndex: 'projectName',
          ellipsis: true,
          width: 135
        },
        {
          title: '年度',
          align: 'center',
          dataIndex: 'year_dictText',
          ellipsis: true,
          width: 135
        },
        {
          title: '现属经营团队',
          align: 'center',
          dataIndex: 'bussinessTeamName',
          ellipsis: true,
          width: 135,
        },
        {
          title: '项目承接人',
          align: 'center',
          dataIndex: 'undertakerName',
          ellipsis: true,
          width: 135,
        },
        {
          title: '项目类别',
          align: 'center',
          dataIndex: 'categoryName',
          ellipsis: true,
          width: 135,
        },
        {
          title: '生产团队',
          align: 'center',
          dataIndex: 'productTeamName',
          ellipsis: true,
          width: 135,
        },
        {
          title: '生产部门',
          align: 'center',
          dataIndex: 'executeDepart_dictText',
          ellipsis: true,
          width: 135,
        },
        {
          title: '项目负责人',
          align: 'center',
          dataIndex: 'projectLeader',
          ellipsis: true,
          width: 135,
        },
        {
          title: '应收金额(元)',
          align: 'center',
          dataIndex: 'paymentMoney',
          ellipsis: true,
          width: 135,
        },
        {
          title: '款项类型',
          align: 'center',
          dataIndex: 'paymentName',
          ellipsis: true,
          width: 135,
        },
        {
          title: '已回款(元)',
          align: 'center',
          dataIndex: 'realCollectMoney',
          ellipsis: true,
          width: 135,
        },
        {
          title: '关注后回款(元)',
          align: 'center',
          dataIndex: 'careAfterCollectMoney',
          ellipsis: true,
          width: 135,
        },
        {
          title: '未回款(元)',
          align: 'center',
          dataIndex: 'noCollectMoney',
          ellipsis: true,
          width: 135,
        },
        {
          title: '督办次数',
          align: 'center',
          dataIndex: 'superviseNum',
          ellipsis: true,
          width: 135,
        },
        {
          title: '操作',
          dataIndex: 'action',
          align:"center",
          fixed:"right",
          width:147,
          scopedSlots: {
          filterDropdown: 'filterDropdown',
          filterIcon: 'filterIcon',
          customRender: 'action' }
        }
      ],
      url: {
        list: '/api/erp/project/report/erpReceivableAccountsReportController/queryCareReceivableAccountCountList',
        delete: '/api/erp/project/report/erpReceivableAccountsReportController/delete',
        deleteBatch: '/api/erp/project/report/erpReceivableAccountsReportController/deleteBatch',
        exportXlsUrl: '/api/erp/project/report/erpReceivableAccountsReportController/exportCareNewXls',
        importExcelUrl: 'api/erp/omc/project/erpOmcProject/importExcel',
      },
      dictOptions: {},
      pcaData: '',
      superFieldList: [],
    }
  },
  created() {
    this.pcaData = new Area()
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
    },
  },
  methods: {
    // 应收期间日期禁止
    disabledDate(current) {
      return current && (current < moment('2018').startOf('year') || current > moment().endOf('year'));
    },
    // 点击应收期间
    dateChange (value) {
      this.queryParam.collectionDateBegin = moment(value).startOf('month').format('YYYY-MM-DD hh:mm:ss')
      this.queryParam.collectionDateEnd = moment(value).endOf('month').format('YYYY-MM-DD hh:mm:ss')
    },
    handleExportXlnew(fileName) {
      this.exportLoading = true
      if (!fileName || typeof fileName !== 'string') {
        fileName = '导出文件'
      }
      let param = this.getQueryParams()
      if (param.noCollectMoney) {
        if (param.noCollectMoney == '1') {
          param.noCollectMoney = '0'
        } else {
          param.noCollectMoney = '1'
        }
      }
      if (this.selectedRowKeys && this.selectedRowKeys.length > 0) {
        param['selections'] = this.selectedRowKeys.join(',')
      }
      console.log('导出参数', param)
      downFile(this.url.exportXlsUrl, param).then(data => {
        if (!data) {
          this.$message.warning('文件下载失败')
          return
        }
        if (typeof window.navigator.msSaveBlob !== 'undefined') {
          window.navigator.msSaveBlob(
            new Blob([data], {
              type: 'application/vnd.ms-excel'
            }),
            fileName + '.xls'
          )
        } else {
          let url = window.URL.createObjectURL(
            new Blob([data], {
              type: 'application/vnd.ms-excel'
            })
          )
          let link = document.createElement('a')
          link.style.display = 'none'
          link.href = url
          link.setAttribute('download', fileName + '.xls')
          document.body.appendChild(link)
          link.click()
          document.body.removeChild(link) // 下载完成移除元素
          window.URL.revokeObjectURL(url) // 释放掉blob对象
        }
      }).finally(()=>{
        this.exportLoading = false
      })
    },
    loadData(arg) {
      if (!this.url.list) {
        this.$message.error('请设置url.list属性!')
        return
      }
      // 加载数据 若传入参数1则加载第一页的内容
      if (arg === 1) {
        this.ipagination.current = 1
      }
      var params = this.getQueryParams() // 查询条件
      if (params.noCollectMoney) {
        if (params.noCollectMoney == '1') {
          params.noCollectMoney = '0'
        } else {
          params.noCollectMoney = '1'
        }
      }
      this.loading = true
      getAction(this.url.list, params).then(res => {
        if (res.success) {
          // update-begin---author:zhangyafei    Date:20201118  for：适配不分页的数据列表------------
          this.dataSource = res.result.records || res.result
          if (res.result.total) {
            this.ipagination.total = res.result.total
          } else {
            this.ipagination.total = 0
          }
          //判断是否当前页没有数据且不为第一页
          if (this.dataSource.length == 0 && this.ipagination.current != 1) {
            this.ipagination.current = this.ipagination.current - 1
            this.loadData(this.ipagination.current - 1);
          }
          // update-end---author:zhangyafei    Date:20201118  for：适配不分页的数据列表------------
        } else {
          this.dataSource = [];
          this.ipagination.total = 0
          this.$message.warning(res.message)
        }
        if (res.code === 510) {
          this.$message.warning(res.message)
        }
        this.loading = false
      }).catch(err => {
        this.$message.warning(err.message)
      })
    },
    // 点击查看
    handleEdit (record) {
      this.$refs.supervisionList.handleCancelDetail(record)
    },

    handleClose () {
      this.loadData()
    },
    getPcaText(code) {
      return this.pcaData.getText(code);
    },
  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>
